
package com.heiyu.api.conf;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Component
public class CorsFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig)  {

    }

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException {
        HttpServletResponse response = (HttpServletResponse) res;
        try{
            chain.doFilter(req, res);
        }catch (Exception e){
            e.printStackTrace();
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json; charset=utf-8");
            PrintWriter out = response.getWriter();
            out.println("{\"code\":\"3001\",\"msg\":\"系统繁忙\",\"data\":\"\"}");
            out.close();
        }

    }

    @Override
    public void destroy() {

    }
}

